package cn.xiongxf.feign;

import cn.xiongxf.result.JsonResult;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

@Component  // 交给Spring容器管理
public class CourseFeignClientFallbackFactory implements FallbackFactory<CourseFeignClient> {
    @Override
    public CourseFeignClient create(Throwable throwable) {
        // 打印接口错误，方便查找错误
        throwable.printStackTrace();
        return new CourseFeignClient() {
            @Override
            public JsonResult selectCourseStatusForUser(Long id) {
                return JsonResult.error("熔断触发，课程服务不可用，请稍后再试！");
            }

            @Override
            public JsonResult selectCourseDataForOrder(String courseIdsStr) {
                return JsonResult.error("熔断触发，课程服务不可用，请稍后再试！");
            }
        };
    }
}
